import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {configParams} from '../../../storage-config';

@Injectable({
  providedIn: 'root'
})
export class WarehouseService {
  /**
   * 仓库列表
   */
  public getList_URL = '/whPut/list';

  /**
   * 添加仓库
   */
  public add_URL = '/whPut/save';
  /**
   * 编辑仓库
   */
  public update_URL = '/whPut/update';
  /**
   * 删除仓库
   */
  public del_URL = '/whPut/delete';
  /**
   * 仓库详情
   */
  public get_Item_URL = '/whPut/get/';

  constructor(public httpClient: HttpClient) {

  }

  post(url: any, body: any) {
    return this.httpClient.post(url, body, {headers: configParams.headers});
  }

  get(url: any, params: any) {
    return this.httpClient.get(url, {params, headers: configParams.headers});
  }

  /**
   * 查询仓库列表
   */
  public getList(json: any | null) {
    json.name = json.name.trim();
    return this.post(this.getList_URL, json);
  }

  /**
   * 添加仓库
   */
  public add(json: any | null) {
    return this.post(this.add_URL, json);
  }

  /**
   * 编辑仓库
   */
  public update(json: any | null) {
    return this.post(this.update_URL, json);
  }

  /**
   * 删除仓库
   */
  public del(json: any | null) {
    return this.post(this.del_URL, json);
  }

  /**
   * 仓库详情
   */
  public getItem(id: any | null) {
    const url = `${this.get_Item_URL}${id}`;
    return this.get(url, {});
  }
}
